var page = require('webpage').create(),
    system = require('system'),
    fs = require('fs'),
    url = 'https://gupiao.baidu.com/api/stocks/stocktimeline?from=pc&os_ver=1&cuid=xxx&vv=100&format=json&stock_code=sz300519&timestamp=1469702157490',
    t = Date.now();

function writeChat(model) {
  var file = fs.open("single.json", 'r');
  console.log(file.read());
  file.close();
  file = fs.open("single.json", 'w');
  file.write(JSON.stringify(model));
  file.close();
}

function consoleText() {
  console.log('url => ' + url);
  page.open(url, function(status) {

    if (status !== 'success') {
      console.log('抓取错误');
    } else {
      console.log('抓取成功');

      var item = page.evaluate(function() {
        var list = [];
        var data = document.querySelectorAll('body');
        list.push(data);
        return list;
      });

      writeChat(item);
      // setTimeout(function() {
      //   consoleText();
      // }, 6000);
    }

    phantom.exit();
  });
}

consoleText();
// pushChat();
